const API_KEY = "770e1be9dd8196f7877303dd3a0d49a5";

// 地理编码：地名转经纬度，支持 city 参数
export async function geocode(address, city = '') {
  let url = `https://restapi.amap.com/v3/geocode/geo?address=${encodeURIComponent(address)}&key=${API_KEY}`;
  if (city) {
    url += `&city=${encodeURIComponent(city)}`;
  }
  const res = await fetch(url);
  const data = await res.json();
  if (data.geocodes && data.geocodes.length > 0) {
    return data.geocodes[0].location; // "经度,纬度"
  }
  return '';
}

// 步行路线规划
export async function getWalkingRoute(origin, destination) {
  const url = `https://restapi.amap.com/v3/direction/walking?origin=${origin}&destination=${destination}&key=${API_KEY}`;
  const res = await fetch(url);
  const data = await res.json();
  return data;
} 